package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketIssue;
import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.IssuePageInfo;
import com.cskaoyan.bean.common.OrderPageInfo;
import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @ClassName:AdminIssueController
 * @Description:TODO
 * @author:leiwenjie
 * @date:2022/9/8 16:14
 * @version:1.0
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {

    @Autowired
    IssueService issueService;


    @RequestMapping("list")
    public BaseRespVo list(IssuePageInfo info) {
        CommonData<MarketIssue> data = issueService.query(info);
        return BaseRespVo.ok(data);
    }

    // 时间需要解决
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map<String, String> map) {
        String question = map.get("question");
        String answer = map.get("answer");

        MarketIssue marketIssue = new MarketIssue();
        marketIssue.setQuestion(question);
        marketIssue.setAnswer(answer);
        Date date = new Date();
        marketIssue.setAddTime(date);
        marketIssue.setUpdateTime(date);
        issueService.create(marketIssue);


        return BaseRespVo.ok(marketIssue);

    }

    // updatetime待解决
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketIssue issue) {
        issueService.update(issue);
        return BaseRespVo.ok(issue);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketIssue issue) {
        issueService.delete(issue);
        return BaseRespVo.ok(null);
    }
}
